package tomcat;

import java.io.File;

import org.apache.catalina.startup.Tomcat;

public class TomcatMain {
	public static void main(String[] args) throws Exception {
		int port = 8089;
		String contextPath = "/opp-service";
		
		Tomcat tomcat = new Tomcat();
		String projectPath = new File("").getAbsolutePath();
		// Embeded tomcat存放路径
		tomcat.setBaseDir(projectPath +"/target"); 
		tomcat.setPort(port);
		// 应用存放路径
		tomcat.addWebapp(contextPath, projectPath + "/src/main/webapp");
		
		// 启动tomcat
		tomcat.start(); 
		
		System.out.println("==========begin===========");
		System.out.println("项目路径: " + projectPath);
		System.out.println("项目名称: " + new File(projectPath).getName());
		System.out.println();
		System.out.println("测试首页");
		System.out.println(String.format("http://localhost:%s%s/index.jsp", port, contextPath));
		System.out.println();
		System.out.println("在线测试文档");
		System.out.println(String.format("http://localhost:%s%s/doc.html", port, contextPath));
		// 让线程一直运行
		tomcat.getServer().await(); 
	}
}
